<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ include file="/include/header.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>增加运价预警设置</title>
<script	src="<%=request.getContextPath()%>/fare/lib/jquery/jquery.form.js"	type="text/javascript"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/show.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/datePicker/WdatePicker.js"></script>
<link href="<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/fare/js/cityquery/citylist.js" type="text/javascript"></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script>
<script type="text/javascript"
	src="<%=request.getContextPath() %>/jsFile/wait/js/wait.js"></script>	
<link rev="stylesheet" media="all" href="<%=request.getContextPath() %>/fare/css/form_style.css" type="text/css" rel="stylesheet">
<link href="<%=request.getContextPath() %>/fare/css/base.css" rel="stylesheet" type="text/css" />
<!-- 圆角文本框 -->
<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" />
</head>
<script >
function saveConfig(){
	//让原本隐藏起来的div显示出来
	//document.getElementById("save").style.display="block";
	var flightFrom = $("#depCity").val();
	var flightTo = $("#arrCity").val();
	if(flightFrom=="" || flightTo =="" || flightFrom=="<s:i18n name='forms'><s:text name='forms.cnOrPingYing'></s:text></s:i18n>" || 
			flightTo =="<s:i18n name='forms'><s:text name='forms.cnOrPingYing'></s:text></s:i18n>"){
		alert("<s:i18n name='forms'><s:text name='forms.chooseRoutes'></s:text></s:i18n>");
		return;
	}
	
	//alert(flightFrom);
	//alert(flightTo);
	if(flightFrom==flightTo){
		alert("<s:i18n name='forms'><s:text name='forms.sameCity'></s:text></s:i18n>");
		return ;
	}
	var effectiveFrom = $("#_effectiveFrom").val();
	var effectiveTo   = $("#_effectiveTo").val();
	var s_date = new Date(effectiveFrom.replace(/-/g,"/"));
    var e_date = new Date(effectiveTo.replace(/-/g,"/"));
    var alertWay = $("#_alertWay").val();
    
    //未来天数为正整数
    var futureDays = $("#_futureDays").val();
    var triggerCondition = $("#_triggerCondition").val();
    if(futureDays==null||$.trim(futureDays)==''||triggerCondition==null||$.trim(triggerCondition)==''){
    	alert('<s:i18n name="forms"><s:text name="forms.triggerFilled"></s:text></s:i18n>');
    	return false;
    }
    
    if(!(/(^[1-9]\d*$)/.test(futureDays))){
    	alert("<s:i18n name='forms'><s:text name='forms.positiveDays'></s:text></s:i18n>");
    	$("#_futureDays").val('');
    	return false;
    }
    
    if(parseInt(futureDays)>30||parseInt(futureDays)<1){
    	alert("<s:i18n name='forms'><s:text name='forms.rangeDays'></s:text></s:i18n>"+"1~30");
    	return false;
    }
    
    //触发 条件 天数为正整数
    if(!(/(^[1-9]\d*$)/.test(triggerCondition))){
    	alert("<s:i18n name='forms'><s:text name='forms.positiveDays'></s:text></s:i18n>");
    	$("#_triggerCondition").val('');
    	return false;
    }
    if(futureDays!=null&&triggerCondition!=null){
    	var conditionTime=parseInt(triggerCondition);//触发时间
    	var futureTime=parseInt(futureDays);
    	if((futureTime+1)<conditionTime&&conditionTime>1){
    		alert("<s:i18n name='forms'><s:text name='forms.maxDays'></s:text></s:i18n>");
    		return false;
    	};
    }
    
    var time1 = s_date.getTime();
	var time2 = e_date.getTime();
	if(effectiveFrom==""||effectiveTo==""||alertWay==""||futureDays==""||triggerCondition==""){
		alert("<s:i18n name='forms'><s:text name='forms.unfilledContents'></s:text></s:i18n>");
		return;
	}
	if(time1>time2){
		alert("<s:i18n name='forms'><s:text name='forms.endTimeBeforeStart'></s:text></s:i18n>");
		return;
	}
	
	/* $.post('freightPriceAnalyseAlertConfigAction!saveFreightPriceAnalyseAlertConfig.action',
				$("#formSave").serialize(),
				function(data){
			if(data && data=="succes"){
				alert('保存成功');
				FDCWait.hide();
				window.returnValue = "ok";
				window.close();
			}else{
				FDCWait.hide();
				alert('保存失败!\n原因：'+data);
			}
	},'text'); */
	$("#formSave").ajaxSubmit({
		   url:"freightPriceAnalyseAlertConfigAction!saveFreightPriceAnalyseAlertConfig.action",
	    	type:"POST",
	    	async:false,
	    	cache : false, 
	    	 beforeSend:function(){	FDCWait.show(); },
	    	success:function(data){
	    		closeCheckedWindow();
	    	},
	    	 error:function(){
	    		 alert("<s:i18n name='forms'><s:text name='forms.failure'></s:text></s:i18n>");
	    	 },
	 	    complete:function(){FDCWait.hide();}
	    });
}	
function closeCheckedWindow(){
	alert("<s:i18n name='forms'><s:text name='forms.success'></s:text></s:i18n>");
	
	var ppWin = window.parent.dialogArguments.pWin;//父窗口
	ppWin.showDataAgain();
	window.parent.close();
}

function resetForm(){
	
	
	//var now = new Date(); //或全今天的日期-显示为日期和时间
	//now.setTime(now.getTime()+24*60*60*1000);
	//var dateValue=now.getFullYear() + "-"+ (now.getMonth()+1)+"-"+(now.getDate()); //获取年月日

	//$("#_effectiveFrom").val(dateValue);
	//$("#_effectiveTo").val(dateValue);
	
	//$("#_flightFrom").val("中文/拼音");
	//$("#_flightTo").val("中文/拼音");
	
	//$("#_triggerCondition").val('');
	//$("#_futureDays").val('');
	
	
	$("#_effectiveFrom").val("");
	$("#_effectiveTo").val("");
	
	$("#depCity").val("");
	$("#arrCity").val("");
	
	$("#_triggerCondition").val('');
	$("#_futureDays").val('');
	
}

function getBack(){
	//让原本隐藏起来的div显示出来
	document.getElementById("save").style.display="none";
}

$(function(){
	var now = new Date(); //或全今天的日期-显示为日期和时间
	var now = new Date(); //或全今天的日期-显示为日期和时间
	now.setTime(now.getTime()+24*60*60*1000);
	var dateValue=now.getFullYear() + "-"+ (now.getMonth()+1)+"-"+(now.getDate()); //获取年月日
    var nextYear = now.getFullYear() + 1;
	var nextDateValue = nextYear + "-"+ (now.getMonth()+1)+"-"+(now.getDate()); 
//	$("#_airCompany").
	
	
	$("#_effectiveFrom").val(dateValue);
	$("#_effectiveTo").val(nextDateValue);
	
	$('#flightFrom').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
	$('#flightTo').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
	
	$('#depCity').querycity({'data':citysFlight,'tabs':labelFromcity});
	$('#arrCity').querycity({'data':citysFlight,'tabs':labelFromcity});
	
	$('#flightFrom0').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
	$('#flightTo0').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
	
	
	
	$("#depCity").css({
		"color":"black"
	});
	$("#arrCity").css({
		"color":"black"
	});
});
function closeWindow(){
	if(window.confirm("<s:i18n name='forms'><s:text name='forms.closeCurrentWindow'></s:text></s:i18n>")){
		window.close();
	}
}
 // 

//离开页面事件
$(window).unload(function (){
	if(window._save==true){
		var parentWindow = window.dialogArguments;//父窗口
		parentWindow.location.href = parentWindow.location.href
	}
//window.opener.location.href = window.opener.location.href;
});
</script>
<body>
	<!-- 增加  -->
	<div id="save">
		<form id="formSave"   method="post"  target="_parent"  autocomplete="off">
			<input type="hidden" id="id" name="id" value="${id}"/>
			<input type="hidden" id="isUpdate" name="isUpdate" value="${isUpdate}"/>
			<TABLE cellSpacing=1 cellPadding=3 width="100%" border=0 class="form_table">
					<TR >
						<TD class="left" colspan="10" ><s:i18n name='forms'><s:text name='forms.lowestAlert'></s:text></s:i18n>
						<s:i18n name='forms'><s:text name='forms.setting'></s:text></s:i18n>
						</TD>
					</TR>
					<TR>
						<TD width="100" height="100" style="text-align: left" class="left">
							<s:i18n name="forms"><s:text name="forms.explanation"></s:text></s:i18n>：</TD>
						<TD colspan="3" >1、<s:i18n name="forms"><s:text name="forms.redAsterisk"></s:text></s:i18n><br/>
							2、<s:i18n name="forms"><s:text name="forms.lowestAlertSetting2"></s:text></s:i18n><br/>
							3、<s:i18n name="forms"><s:text name="forms.lowestAlertSetting3"></s:text></s:i18n><br/>
							4、<s:i18n name="forms"><s:text name="forms.lowestAlertSetting4"></s:text></s:i18n><br/>
						</TD>
					</TR>
					
				<TR >
					<TD width="100" height="26" class="left" style="text-align:left">
						<s:i18n name="forms"><s:text name="forms.airlines"></s:text></s:i18n>：
				    	<span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;*</span>
				    </TD>
				    <TD colspan="3" >
				     &nbsp;&nbsp;&nbsp;&nbsp;
				       <select class="easyui-combobox" name="airCompany" style="width: 150px;" id="_airCompany" disabled="disabled">
								<c:choose>
									<c:when test="${tempList == null}">
									</c:when>
									<c:otherwise>
										<c:forEach var="item" items="${tempList}">
											<option>${item.name}</option>
										</c:forEach>
									</c:otherwise>
								</c:choose>
						</select>
				    </TD>
			    </TR>
			    
			    <TR >
				    <TD width="100" class="left" style="text-align:left"><s:i18n name="forms"><s:text name="forms.trip"></s:text></s:i18n>：
				    <font color="red">&nbsp;&nbsp;&nbsp;&nbsp;*</font>
				    </TD>
				    <TD colspan="3" >
				    <c:if test="${language=='en_US'}">
				    <jsp:include page="/inc/flightSelect_en_Us.jsp"></jsp:include>
				    </c:if>
				    <c:if test="${language=='zh_CN' or language=='other'}">
				    <jsp:include page="/inc/flightSelect.jsp"></jsp:include>
				    </c:if>
				     
				     <%--  <span>从</span>
				      <input type="text" style="width:100px" name="flightFrom" id="_flightFrom" value="${vo.fromCityName}">
				      <span>到</span>
				      <input type="text" style="width:100px" name="flightTo" id="_flightTo" value="${vo.toCityName}">&nbsp;&nbsp;&nbsp; --%>
				    </TD>
			  	</TR>
			  	
			  <TR style="display: none;">
				  	<TD width="100" height="26" class="left" style="text-align:left"><s:i18n name="forms"><s:text name="forms.alertMode"></s:text></s:i18n>：
				  	<span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;*</span>
				    </TD>
				    <TD >
				    	 &nbsp;&nbsp;&nbsp;&nbsp;
				      	<select class="easyui-combobox" name="alertWay" style="width: 150px;" id="_alertWay" disabled="disabled">
								<option value="1" selected="selected"><s:i18n name="forms"><s:text name="forms.mail"></s:text></s:i18n></option>
								<option value="0"><s:i18n name="forms"><s:text name="forms.SMS"></s:text></s:i18n></option>
						</select>
				    </TD>
				    <%-- <TD colspan="2" height="26" style="text-align:left">
				    		未来天数：
				    		 <span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;*</span>
				    		 <input type="text" style="width:100px" name="futureDays" id="_futureDays" value="">
				    		 天
				    </TD> --%>
				    <!-- <TD >
				      <input type="text" style="width:100px" name="futureDays" id="_futureDays" value="">
				    </TD> -->
			  </TR>
			  
			  <TR >
				    <TD width="100" height="26" class="left" style="text-align:left" ><s:i18n name="forms"><s:text name="forms.alertValid"></s:text></s:i18n>：
				          <font color="red">*</font>
				    </TD>
				    <TD colspan="3" >
				      <span><s:i18n name="forms"><s:text name="forms.from"></s:text></s:i18n></span>
				       <input type="text" style="width:80px" id="_effectiveFrom" name="effectiveFrom" value="${vo.startTime }" 
				      	onClick="WdatePicker({skin:'whyGreen',lang:'<s:text name='forms.locale'/>',dateFmt:'yyyy-MM-dd',minDate:'%y-%M-{%d+1}'});" readonly="readonly">
				      <span><s:i18n name="forms"><s:text name="forms.to"></s:text></s:i18n></span>
				      <input type="text" style="width:80px" id="_effectiveTo" name="effectiveTo" value="${vo.endTime }" 
				      	onClick="WdatePicker({skin:'whyGreen',lang:'<s:text name='forms.locale'/>',dateFmt:'yyyy-MM-dd',minDate:'%y-%M-{%d+1}'});" readonly="readonly"> 
					</TD>
			  </TR>
			  
			  <TR >
			  	<TD width="100" height="26" class="left" style="text-align:left">
			  			<s:i18n name="forms"><s:text name="forms.triggeringConditions"></s:text></s:i18n>：<span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*</span>
			    </TD>
			    <TD  colspan="2" height="26" style="text-align:left">
			    			<s:i18n name="forms"><s:text name="forms.tripinthenext"></s:text></s:i18n>
				    		 <input type="text" style="width:50px" name="futureDays" id="_futureDays" value="${vo.futureDays }">
							<s:i18n name="forms"><s:text name="forms.daysOftheprice"></s:text></s:i18n>
							<input type="text" style="width:50px" name="triggerCondition" id="_triggerCondition" value="${vo.triggerCondition}">
							<s:i18n name="forms"><s:text name="forms.days"></s:text></s:i18n>
							<select class="easyui-combobox" name="chooseUpOrdown" id="up_down" >
								<option value="0" selected="selected"><s:i18n name="forms"><s:text name="forms.following"></s:text></s:i18n></option>
								<option value="1" ><s:i18n name="forms"><s:text name="forms.above2"></s:text></s:i18n></option>
							</select>
							<s:i18n name="forms"><s:text name="forms.isTheLowest"></s:text></s:i18n>
							
				</TD>
			    <!-- <TD colspan="3"  height="26">
			    		当天抓抓取到的航线未来各天的各最低价中，我航少于
			    		<input type="text" style="width:100px" name="triggerCondition" id="_triggerCondition" value="">天
			    </TD> -->
			    <!-- <TD >
			      <input type="text" style="width:100px" name="triggerCondition" id="_triggerCondition" value="">天
			    </TD> -->
			  </TR>
			    
			  <TR>
			  		<TD style="text-align: center" colspan="4" class="left">
			  			 <input type="button" style="width:80px" id="btnSave" name="btnSave" 
			  			 	value="<s:i18n name='forms'><s:text name='forms.save'></s:text></s:i18n>" onclick="saveConfig()" />
			  			 <input type="button" style="width:80px" id="btnReset" name="btnReset" 
			  			 value="<s:i18n name='forms'><s:text name='forms.cleared'></s:text></s:i18n>" onclick="resetForm()"/>
			  			<!--  <input type="button" style="width:80px" id="btnClose" name="btnClose" value="关闭" onclick="closeWindow();" />  -->
			  		</TD>
			  </TR>
			</table>
		</form>
	</div>
</body>
</html>